Show budget spend and threshold in ucode usage - #261
Open
andy-xu-db wants to merge 3 commits into
Open
Conversation
`ucode usage` reported tokens only, with no dollar figure. Surface the caller's
live coding-agent budget spend against its alert threshold, from the AI Gateway
`coding-agent-configs:resolveCurrentBudgetSpend` endpoint.
Budget spend: $12.34 of $100.00 (12%)
[███░░░░░░░░░░░░░░░░░░░░░░░░░░░]
- databricks.py: `resolve_current_budget_spend` POSTs an empty body (caller and
workspace come from the bearer) and parses both amounts as `Decimal`. Absence
is the common case — the endpoint is behind a per-org SAFE flag (default off),
needs a coding-agent config, and returns both fields unset when no budget
matches — so all of it comes back as a reason string, never an exception. A
spend without a threshold counts as no spend, mirroring the server's
`BudgetSpend.fromProto`.
- ui.py: `format_usd` (half-up to cents) and `format_meter` (clamped to [0, 1];
a nonzero fraction fills at least one cell so a small real spend doesn't read
as an empty bar).
- usage.py: `render_budget_lines` + a `budget_spend` arg on
`render_usage_summary`. Unavailable spend omits the lines rather than failing
the report; a zero threshold shows the bare amount, since there is no whole to
be a fraction of.
Co-authored-by: Isaac
andy-xu-db
force-pushed
the
andy/update-ucode-usage
branch
from
August 3, 2026 22:32
55973b2 to
68d3b5b
Compare
andy-xu-db
marked this pull request as ready for review
August 4, 2026 20:01
andy-xu-db
marked this pull request as draft
August 4, 2026 21:04
andy-xu-db
marked this pull request as ready for review
August 4, 2026 21:04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ucode usageshows tokens only — no dollar spend or budget context.Change
Add the caller's coding-agent budget spend and alert threshold to the
ucode usagesummary, read off AI Gateway'scoding-agent-configs:recommendModel(posted with an emptyavailable_models, since we want the spend the recommendation was based on, not the recommendation —recommended_modelsis ignored):Amounts are parsed as
Decimal. The endpoint is off by default per org, so absence returns a reason string rather than raising — the lines are simply omitted and the rest of the report is unchanged.Testing
29 new unit tests; 1167 passed, ruff clean.
Verified against the live endpoint on a workspace with the flag on:
current_spend2.3441188/effective_threshold5000renders as$2.34 of $5,000.00 (0%). A workspace with the flag off returnsFEATURE_DISABLEDand correctly renders no lines.